import { HttpDelRule, HttpRuleList, HttpSetActiveRule } from '../../../service/notice'
import TableList from '../../../components/templates/tablelist'
import { mapGetters } from 'vuex'
import mixin from '../mixin'

export default {
    mixins: [TableList, mixin],
    data () {
        return {
            isMixin: true,
            Tools: { show: true },
            Searchs: {
                show: true,
                labelWidth: 90,
            },
            Plugins: { show: true },
        }
    },
    methods: {
        ajaxRequest: HttpRuleList,
        handleOperates (params, type) {
            // if (batch === true) {
            //     params = (params || this.checkedData.join(',')) + '';
            //     if (!params.length) return this.$Message.warning('请选择至少一条数据');
            // }
            switch (type) {
                case 'del':
                    this.operate = {
                        show: false,
                        alert: 'error',
                        params: { id: params },
                        title: '删除通知规则',
                        ajaxRequest: HttpDelRule,
                    }
                    break
                case 'setActive':
                    this.operate = {
                        show: true,
                        alert: (params.active == 1) ? 'success' : 'error',
                        params,
                        title: (params.active == 1 ? '启用' : '禁用') + '该条目',
                        ajaxRequest: HttpSetActiveRule
                    }
                    break
            }
        },
        // 操作下的列表展示内容
        getOperateNodeMap (row) {
            const { id, active } = row
            return [{
                label: '查看',
                show: true,
                to: {
                    name: 'noticeRulesUpdate',
                    params: { type: 'query' },
                    query: { id },
                },
            }, {
                label: '编辑',
                show: true,
                to: {
                    name: 'noticeRulesUpdate',
                    params: { type: 'edit' },
                    query: { id },
                },
            }, {
                label: '失效',
                show: false,
                params: id,
                operate: 'invalid'
            }, {
                label: '删除',
                show: false,
                params: id,
                operate: 'del'
            }, {
                label: active == 1 ? '禁用' : '启用',
                show: true,
                params: { id, active: active == 1 ? 2 : 1 },
                operate: 'setActive'
            }
            ]
        },
    },
    computed: {
        ...mapGetters('dictionary', ['getProductList', 'getAccountList', 'getWarehouseList']),
        ...mapGetters(['isSuper']),
        ToolsData () {
            return [
                {
                    label: '添加',
                    theme: 'primary',
                    to: {
                        name: 'noticeRulesUpdate',
                        params: { type: 'add' },
                    }
                },
                {
                    label: '规则测试',
                    theme: 'success',
                    show: this.isSuper,
                    to: {
                        name: 'noticeRulesTest',
                    }
                }
            ]
        },
        SearchsData () {
            return [
                // {
                //     label: "日期",
                //     key: "BT_createdAt",
                //     tag: "autoDatepicker",
                //     props: {
                //         confirm: false,
                //         type: "daterange"
                //     },
                //     // showLabel: true,
                //     style: {
                //         "width": "180px"
                //     },
                //     on: {
                //         "change": (val) => {
                //             console.log('on-change', val);
                //         },
                //     },
                //     show: true,
                // },
                {
                    label: '规则名称',
                    key: 'EQ_title',
                    tag: 'Input',
                    show: true,
                },
                {
                    label: '类型',
                    key: 'EQ_bizeventTypeId',
                    tag: 'Select',
                    show: true,
                    options: this.getNoticeEevntTypes,
                },
                // {
                //     label: "关联模板",
                //     key: 'EQ_tplId',
                //     tag: 'Input',
                //     show: true,
                //     // options: this.getNoticeEevntTypes
                // },
                {
                    label: '状态',
                    tag: 'Select',
                    key: 'EQ_active',
                    options: this.getRuleStatus
                },
                // {
                //     label: "通知人",
                //     tag: 'Select',
                //     key: 'EQ_toSourceCreator',
                //     options: this.getNotifierList
                // },
                {
                    label: '项目',
                    tag: 'Select',
                    key: 'EQ_matchLineId',
                    options: this.getProductList,
                    props: {
                        filterable: true,
                    }
                },
                {
                    label: '渠道',
                    tag: 'Select',
                    key: 'EQ_matchAccountId',
                    options: this.getAccountList,
                    props: {
                        filterable: true,
                    }
                },
                {
                    label: '仓库',
                    tag: 'Select',
                    key: 'EQ_matchOrgwarehouseId',
                    options: this.getWarehouseList,
                    props: {
                        filterable: true,
                    }
                },
                {
                    label: '创建人',
                    tag: 'Input',
                    key: 'EQ_createdName',
                },
            ]
        },
        columns () {
            return [
                // {
                //     type: 'selection',
                //     width: 40,
                //     align: 'center',
                //     formName: 'id'
                // },
                {
                    title: '操作',
                    width: 110,
                    render: this.getOperateNodes
                }, {
                    title: 'ID',
                    key: 'id',
                    width: 70,
                }, {
                    title: '规则名称',
                    key: 'title',
                }, {
                    title: '规则描述',
                    key: 'brief',
                }, {
                    title: '类型',
                    key: 'bizeventTypeId',
                    render: (h, { row }) => this.findRenderLabel(this.getNoticeEevntTypes, row.bizeventTypeId),
                },
                // {
                //     title: '关联模板',
                //     key: 'tplId',
                // },
                {
                    title: '状态',
                    key: 'active',
                    render: (h, { row }) => this.findRenderLabel(this.getRuleStatus, row.active),
                },
                {
                    title: '创建时间',
                    key: 'createdAt',
                }, {
                    title: '更新时间',
                    key: 'updatedAt',
                }]
        },
    },
}




